package com.leesche.netdoll.communication;

import org.apache.commons.configuration2.Configuration;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.leesche.framework.core.configuration.ConfigurationUtil;

public class Settings {

	private static final Logger logger = LogManager.getLogger(Settings.class);

	public static void loadSettings() {

		logger.info("loading server configurations...");

		Configuration conf = ConfigurationUtil.loadProperties("server.properties");

		ServerConfig.BOSS_SIZE = conf.getInt("netty.boss.size");
		ServerConfig.WORKER_SIZE = conf.getInt("netty.worker.size");
		ServerConfig.IP = conf.getString("netty.server.ip");
		ServerConfig.PORT = conf.getInt("netty.server.port");
		ServerConfig.TIMEOUT = conf.getInt("netty.timeout");

		RedisModule.TERMINAL = conf.getString("redis.module.terminal");
		// RedisModule.KEY_DEVICE_IDLE = conf.getString("redis.key.device.idle");
		RedisModule.KEY_GS = conf.getString("redis.key.gs");
		RedisModule.KEY_DS = conf.getString("redis.key.ds");
		RedisModule.KEY_OUTBOUND = conf.getString("redis.key.outbound");

		SenderConfig.OUTBOUND_THREAD = conf.getInt("sender.outbound.thread");

		ProcessorConfig.GS_THREAD = conf.getInt("processor.gs.thread");
		ProcessorConfig.GS_BUFFER_SIZE = conf.getInt("processor.gs.buffer.size");
		ProcessorConfig.GS_BUFFER_MAX_CONSUME = conf.getInt("processor.gs.buffer.max.consume");

		logger.info("loading server configurations...OK");
	}

	public final static class ServerConfig {

		public static int BOSS_SIZE;
		public static int WORKER_SIZE;
		public static String IP;
		public static int PORT;
		public static int TIMEOUT;
	}

	public final static class RedisModule {
		public static String TERMINAL;

		// public static String KEY_DEVICE_IDLE;
		public static String KEY_GS;
		public static String KEY_DS;
		public static String KEY_OUTBOUND;
	}

	public final static class SenderConfig {
		public static int OUTBOUND_THREAD;
	}

	public final static class ProcessorConfig {
		public static int GS_THREAD;
		public static int GS_BUFFER_SIZE;
		public static int GS_BUFFER_MAX_CONSUME;
	}
}
